/*
 * @Author: [wsn] [1741415861@qq.com]
 * @Date: 2023-04-25 13:10:58
 * @LastEditors: [wsn] [1741415861@qq.com]
 * @LastEditTime: 2023-05-19 17:52:10
 * @FilePath: \202304fgs_project\src\components\threejsTools\Tools\LoadobjModel.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
import { Vector3 } from "three";
export default async function LoadModelPromise(obj: any, mtl: any, x: number, y: number, z: number,scalex:number,scaley:number,scalez:number) {
  console.log('LoadModel我执行了');
  let propsobj = new Promise(function (resolve, reject) {
    var objloader = new OBJLoader();//obj加载器
    var mtlloader = new MTLLoader();//材质文件加载器
    mtlloader.load(mtl, function (materials) {
      objloader.setMaterials(materials);
      objloader.load(obj, function (obj) {
        obj.position.set(x,y,z);//x, y, z,2,-1,0
        obj.scale.set(scalex,scaley,scalez)
        console.log(obj,'obj');
        // obj.translateY(-1.5);
        // obj.translateZ(-0.5);
        window.threescene.add(obj);//返回的组对象插入场景中
        // obj.children[0].scale.set(135, 135, 135);//网格模型缩放
        // obj.children[0].scale.set(0.5, 0.5, 5);
        window.meshobj = obj;
        resolve(obj);
      })
    })
  })
  return propsobj;
}